home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / mc51bugs / q32557 < prev    next >
Text File  |  1988-07-20  |  1KB  |  46 lines

  1. Q32557 Comparison of Result of Pointer Subtraction Inconsistent
  2. C Compiler
  3. 5.10   | 5.10
  4. MS-DOS | OS/2
  5.  
  6. Summary:
  7.    The following program attempts to compare two pointers. When the
  8. value is assigned to a variable, the comparison works correctly;
  9. however, when the comparison is performed directly to zero, the test
  10. fails.
  11.    The compiler is incorrectly making a signed comparison of the
  12. pointers b and a.
  13.    Microsoft has confirmed this to be a problem in Version 5.10 of the
  14. C compiler. We are researching this problem and will post new
  15. information as it becomes available.
  16.    You can work around this problem by using the first form; i.e., make
  17. the assignment of the comparison to a variable and then check that
  18. value against zero.
  19.  
  20. More Information:
  21.    The following program demonstrates the problem:
  22.  
  23. #include <stdio.h>
  24. #include <dos.h>
  25. main()
  26. {
  27.  unsigned char far *a,far *b;
  28.  int a;
  29.  FP_SEG(a) = 0x1baf;
  30.  FP_OFF(a) = 0x7f32;
  31.  FP_SEG(b) = 0x1baf;
  32.  FP_OFF(b) = 0x8446;
  33.  
  34.   if((a = b-a)>0)
  35.    printf("(a = b-a) is OK\n");
  36.   if((b-a) > 0)
  37.    printf("(b-a) is OK\n");
  38.   else
  39.    printf("(b-a) is not OK\n");
  40. }
  41.  
  42.  
  43.  
  44. Keywords:  buglist5.10 qfbv
  45. Updated  88/07/21 03:19
  46.